/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.Locale;
import metier.ResponseForm;

/**
 *
 * @author Alex
 */
public class Claim {
    protected static Integer numberOfClaim = 1;
    
    protected Integer idClaim;
    protected Status status;
    protected Customer customer;
    protected Collection<Expense> expenses;
    protected Float expensesTotalPaidByCustomer;
    protected Float expensesTotalToReimburse;
    protected GregorianCalendar accidentDate;
    protected Responsibility responsibility;
    protected ResponseForm responseForm;

    public Claim() {
        status = Status.REGISTERED;
        expenses = new ArrayList<>();
        expensesTotalPaidByCustomer = (Float)0.0f;
        expensesTotalToReimburse = (Float)0.0f;
        accidentDate = new GregorianCalendar(Locale.FRANCE);
        responsibility = Responsibility.NOTRESPONSIBLE;
        responseForm = null;
        
    }
    
    public Claim(Claim claim) {
        this.idClaim = claim.idClaim;
        this.customer = claim.customer;
        this.expenses = claim.expenses;
        this.expensesTotalPaidByCustomer = claim.expensesTotalPaidByCustomer;
        this.expensesTotalToReimburse = claim.expensesTotalToReimburse;
        this.accidentDate = claim.accidentDate;
        this.responsibility = claim.responsibility;
        responseForm = null;
    }
    
    public static Integer getNumberOfClaim() {
        return numberOfClaim;
    }

    public static void incrementNumberOfClaim() {
        numberOfClaim++;
    }

    public ResponseForm getResponseForm() {
        return responseForm;
    }

    public void setResponseForm(ResponseForm responseForm) {
        this.responseForm = responseForm;
    }
    
    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Collection<Expense> getExpenses() {
        return expenses;
    }

    public void setExpenses(Collection<Expense> expenses) {
        this.expenses = expenses;
    }

    public Float getExpensesTotalPaidByCustomer() {
        return expensesTotalPaidByCustomer;
    }

    public void setExpensesTotalPaidByCustomer(Float expensesTotalPaidByCustomer) {
        this.expensesTotalPaidByCustomer = expensesTotalPaidByCustomer;
    }

    public Float getExpensesTotalToReimburse() {
        return expensesTotalToReimburse;
    }

    public void setExpensesTotalToReimburse(Float expensesTotalToReimburse) {
        this.expensesTotalToReimburse = expensesTotalToReimburse;
    }

    public Integer getIdClaim() {
        return idClaim;
    }

    public void setIdClaim(Integer idClaim) {
        this.idClaim = idClaim;
        /* Temporary code while no DB */
        incrementNumberOfClaim();
    }

    public void addExpense(Expense exp) {
        expenses.add(exp);
        expensesTotalPaidByCustomer += exp.getAmountPaidByCustomer();
    }

    public GregorianCalendar getAccidentDate() {
        return accidentDate;
    }

    public void setAccidentDate(GregorianCalendar accidentDate) {
        this.accidentDate = accidentDate;
    }
    
        public Responsibility getResponsibility() {
        return responsibility;
    }

    public void setResponsibility(Responsibility responsibility) {
        this.responsibility = responsibility;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
        
    public void treat() {
        /* Reimburse 100% to simplify */
        expensesTotalToReimburse = expensesTotalPaidByCustomer;
    }
    
    public String toString() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        return "id : "+this.idClaim+"; customer : "+this.customer+"; total expenses : "+this.expensesTotalToReimburse+"; date : "+sdf.format(this.accidentDate.getTime())+"; responsability : "+this.responsibility;
    }
    
    public Boolean isResponseFormSet() {
        return responseForm == null ? false : true;
    }
    
    public enum Status {
    REGISTERED, CLASSIFIED, FORMFILLED, INSURANCECHECKED, DAMAGEHISTORYCHECKED, GARAGEPHONED, VERIFIED;
    }
    
    public enum Responsibility {
        RESPONSIBLE, NOTRESPONSIBLE;
    }
}
